using System;
using BizElements.BusinessLayer;

namespace BizElements.Web
{
    internal static class BoundControlHelper
    {
        #region IsInReadOnlyMode.

        public static bool IsInReadOnlyMode(FieldAccessMode accessMode, IBindableField bizField)
        {
            bool isReadOnly;
            switch (accessMode)
            {
                case FieldAccessMode.Automatic:
                    if (bizField != null && bizField.IsReadOnly)
                        isReadOnly = true;
                    else
                        isReadOnly = false;
                    break;
                case FieldAccessMode.Edit:
                    isReadOnly = false;
                    break;
                case FieldAccessMode.ReadOnly:
                    isReadOnly = true;
                    break;
                default:
                    throw new Exception("Unsupported field access mode: " + accessMode.ToString() + ".");
            }

            return isReadOnly;
        }

        #endregion
    }
}
